package com.net.xpay.web.controller.merchant.collect;


import com.google.common.base.Preconditions;
import com.net.common.model.ResultData;
import com.net.common.model.ResultList;
import com.net.common.model.ResultPagedList;
import com.net.xpay.common.domain.User;

import com.net.xpay.common.domain.collect.CollectionSafePayChannel;
import com.net.xpay.common.manager.collect.CollectionSafePayChannelManager;
import com.net.xpay.core.model.CollectionSafePayChannelSearchModel;
import com.net.xpay.core.model.CreateCollectionSafePayChannelModel;
import com.net.xpay.core.model.IdModel;
import com.net.xpay.core.model.ModifyCollectionSafePayChannelModel;
import com.net.xpay.core.service.safePay.CollectionSafePayService;
import com.net.xpay.web.secutiry.RequestUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;


@RestController
@Slf4j
@RequestMapping("/merchant/collection-safe-pay-channel")
@Api(tags = "商户/安全付收集收款渠道", description = "商户 安全付收集收款渠道 net")
public class CollectionSafePayChannelController {

    @Autowired
    private CollectionSafePayService collectionSafePayService;

    @Autowired
    private CollectionSafePayChannelManager collectionSafePayChannelManager;


    /**
     * 创建收款渠道
     */
    @ApiOperation("创建收款渠道")
    @PostMapping
    public ResultData<Void> addCollectionSafePayChannel(@ApiIgnore @RequestUser User merchant, @RequestBody CreateCollectionSafePayChannelModel channel) {
        collectionSafePayService.addCollectionSafePayChannel(merchant, channel);
        return new ResultData<>();
    }


    /**
     * 修改渠道信息
     */
    @ApiOperation("修改渠道信息")
    @PostMapping("modify-channel-info")
    public ResultData<Void> modifyCollectionSafePayChannel(@ApiIgnore @RequestUser User merchant, @RequestBody ModifyCollectionSafePayChannelModel channel) {
        collectionSafePayService.modifyCollectionSafePayChannelInfo(merchant, channel);
        return new ResultData<>();
    }

    /**
     * 删除渠道
     */
    @ApiOperation("删除渠道")
    @PostMapping("delete-channel")
    public ResultData<Void> deleteCollectionSafePayChannel(@ApiIgnore @RequestUser User merchant, @RequestBody IdModel idModel) {
        collectionSafePayService.deleteCollectionSafePayChannel(merchant, idModel);
        return new ResultData<>();
    }

    /**
     * 搜索
     */
    @ApiOperation("搜索")
    @PostMapping("/search")
    public ResultPagedList<CollectionSafePayChannel> search(@ApiIgnore @RequestUser User merchant, @RequestBody CollectionSafePayChannelSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);

        searchModel.setUserId(merchant.getId());
        List<CollectionSafePayChannel> records = collectionSafePayChannelManager.search(searchModel);
        long count = collectionSafePayChannelManager.searchCount(searchModel);

        return new ResultPagedList<>(records, count, searchModel);
    }


    /**
     * 列表
     */
    @ApiOperation("列表")
    @PostMapping("/list")
    public ResultList<CollectionSafePayChannel> list(@ApiIgnore @RequestUser User merchant, @RequestBody CollectionSafePayChannelSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);

        searchModel.setUserId(merchant.getId());
        List<CollectionSafePayChannel> records = collectionSafePayChannelManager.list(searchModel);

        return new ResultList<>(records);
    }

}
